﻿<UserControl x:Class="PrestoDashboard.Tabs.SecurityView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:galaSoft="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"
             xmlns:enums="clr-namespace:PrestoCommon.Enums;assembly=PrestoCommon"
             mc:Ignorable="d" 
             d:DesignHeight="600" d:DesignWidth="700">
    <UserControl.DataContext>
        <Binding Source="{StaticResource SecurityViewModel}"/>
    </UserControl.DataContext>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="200"/>
        </Grid.RowDefinitions>

        <DockPanel Grid.Column="0" Grid.RowSpan="2" LastChildFill="True">
            <Label DockPanel.Dock="Top" Style="{StaticResource StandardLabel}" Content="AD Groups" HorizontalAlignment="Center" FontWeight="Bold"/>
            <StackPanel DockPanel.Dock="Bottom" Orientation="Vertical" Height="80" HorizontalAlignment="Center"
                        IsEnabled="{Binding UserCanModifySecurity}">
                <StackPanel Orientation="Horizontal">
                    <Button Style="{StaticResource StandardButton}" Content="Add..." Command="{Binding AddGroupCommand}" Height="20" />
                    <Button Style="{StaticResource StandardButton}" Content="Refresh" Command="{Binding RefreshGroupCommand}" Height="20" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <Button Style="{StaticResource StandardButton}" Content="Delete..." Command="{Binding DeleteGroupCommand}" Height="20" />
                </StackPanel>
            </StackPanel>
            <ListBox DockPanel.Dock="Bottom" ItemsSource="{Binding AdGroupWithRolesList}"
                     DisplayMemberPath="AdGroupName"
                     SelectedItem="{Binding SelectedAdGroupWithRoles}" Height="auto">
            </ListBox>
        </DockPanel>
        <DockPanel Grid.Column="1" Grid.Row="0" LastChildFill="True" IsEnabled="{Binding AdGroupIsSelected}">

            <StackPanel Orientation="Vertical" DockPanel.Dock="Top">

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="25"/>
                        <RowDefinition Height="25"/>
                        <RowDefinition Height="40"/>
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="140"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <Label Grid.Row="0" Grid.ColumnSpan="2" Style="{StaticResource StandardLabel}" Content="Selected AD Group" HorizontalAlignment="Center" FontWeight="Bold"/>

                    <Label Grid.Column="0" Grid.Row="1" Style="{StaticResource StandardLabel}" Content="Name: "/>
                    <TextBox Grid.Column="1" Grid.Row="1" Text="{Binding SelectedAdGroupWithRoles.AdGroupName}" />

                    <Button Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2" Style="{StaticResource StandardButton}" Content="Save"
                            IsEnabled="{Binding UserCanModifySecurity}" Command="{Binding SaveGroupCommand}" />
                </Grid>

            </StackPanel>

            <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Center" IsEnabled="{Binding UserCanModifySecurity}">
                <Button Style="{StaticResource StandardButton}" Content="Add..." Command="{Binding AddRoleCommand}" />
                <Button Style="{StaticResource StandardButton}" Content="Delete..." Command="{Binding RemoveRoleCommand}" />
            </StackPanel>

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="25"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Label Grid.Row="0" Style="{StaticResource StandardLabel}" Content="Roles" FontWeight="Bold"/>
                <DataGrid Grid.Row="1" AutoGenerateColumns="False" IsReadOnly="True" HeadersVisibility="Column"
                      ItemsSource="{Binding PrestoRoles}"
                      SelectedItem="{Binding SelectedPrestoRole}">
                    <DataGrid.Columns>
                        <DataGridTextColumn Binding="{Binding}" Header="Role" Width="*"/>
                    </DataGrid.Columns>
                </DataGrid>
            </Grid>

        </DockPanel>

        <DockPanel Grid.Column="1" Grid.Row="1" LastChildFill="True">

            <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Center">
                <Button Style="{StaticResource StandardButton}" Content="Save" Command="{Binding SaveAdInfoCommand}"
                        IsEnabled="{Binding UserCanModifySecurity}"/>
            </StackPanel>

            <Grid DockPanel.Dock="Top">
                <Grid.RowDefinitions>
                    <RowDefinition Height="25"/>
                    <RowDefinition Height="25"/>
                    <RowDefinition Height="25"/>
                    <RowDefinition Height="25"/>
                    <RowDefinition Height="25"/>
                    <RowDefinition Height="25"/>
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="160"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>

                <Label Grid.Column="0" Grid.Row="0" Style="{StaticResource StandardLabel}" Content="Domain: "/>
                <TextBox Grid.Column="1" Grid.Row="0" Text="{Binding ActiveDirectoryInfo.Domain}" />

                <Label Grid.Column="0" Grid.Row="1" Style="{StaticResource StandardLabel}" Content="Domain suffix: "/>
                <TextBox Grid.Column="1" Grid.Row="1" Text="{Binding ActiveDirectoryInfo.DomainSuffix}" />

                <Label Grid.Column="0" Grid.Row="2" Style="{StaticResource StandardLabel}" Content="Domain port: "/>
                <TextBox Grid.Column="1" Grid.Row="2" Text="{Binding ActiveDirectoryInfo.DomainPort}" />

                <Label Grid.Column="0" Grid.Row="3" Style="{StaticResource StandardLabel}" Content="AD query account user: "/>
                <TextBox Grid.Column="1" Grid.Row="3" Text="{Binding ActiveDirectoryInfo.ActiveDirectoryAccountUser}" />

                <Label Grid.Column="0" Grid.Row="4" Style="{StaticResource StandardLabel}" Content="AD query account password: "/>
                <DockPanel Grid.Column="1" Grid.Row="4" LastChildFill="True">
                    <Button Command="{Binding EncryptCommand}" Style="{StaticResource StandardButton}" Content="Encrypt"
                            VerticalAlignment="Center" Margin="1" Height="22" DockPanel.Dock="Right"/>
                    <TextBox Text="{Binding ActiveDirectoryInfo.ActiveDirectoryAccountPassword}" DockPanel.Dock="Left" />
                </DockPanel>                

                <Label Grid.Column="0" Grid.Row="5" Style="{StaticResource StandardLabel}" Content="Security enabled: "/>
                <CheckBox  Grid.Column="1" Grid.Row="5" Style="{StaticResource StandardCheckBox}"
                           IsChecked="{Binding ActiveDirectoryInfo.SecurityEnabled}"
                           VerticalAlignment="Center" Width="140" HorizontalAlignment="Left"/>

            </Grid>

        </DockPanel>

    </Grid>
</UserControl>
